package cn.formaggie.entity.model.roleandpermission;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;
import java.util.List;

public class Role implements Serializable{

    private Integer id;//主键
    private String roleName;//角色名称（对应于实际的职位）
    private String detail;//角色详细介绍
    @JSONField(serialize = false)
    private List<Permission> permissionList;//角色的权限列表
    @JSONField(serialize = false)
    private List<Worker> workerList;//拥有该角色的工人
    private String permissionStr;//与数据库无关，只用来页面json展示
    private String workerStr;//与数据库无关，只用来页面json展示

    public Role() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public List<Permission> getPermissionList() {
        return permissionList;
    }

    public void setPermissionList(List<Permission> permissionList) {
        this.permissionList = permissionList;
    }

    public List<Worker> getWorkerList() {
        return workerList;
    }

    public void setWorkerList(List<Worker> workerList) {
        this.workerList = workerList;
    }

    public String getPermissionStr() {
        StringBuffer buffer=new StringBuffer();
        for(Permission p:permissionList){
            buffer.append(p.getPermission()+" ，");
        }
        if(buffer.length()>0){
            buffer.deleteCharAt(buffer.length()-1);
        }
        return buffer.toString();
    }

    public void setPermissionStr(String permissionStr) {
        this.permissionStr = permissionStr;
    }

    public String getWorkerStr() {
        StringBuffer buffer=new StringBuffer();
        for(Worker w:workerList){
            buffer.append(w.getWorkerId()+":"+w.getName()+" ，");
        }
        if(buffer.length()>0){
            buffer.deleteCharAt(buffer.length()-1);
        }
        return buffer.toString();
    }

    public void setWorkerStr(String workerStr) {
        this.workerStr = workerStr;
    }

    @Override
    public String toString() {
        return "Role{" +
                "id=" + id +
                ", roleName='" + roleName + '\'' +
                ", detail='" + detail + '\'' +
                ", permissionList=" + permissionList +
                '}';
    }
}
